# 定义要写入文件的内容
filename = "geometric_series.txt"

with open(filename, 'w') as file:
    a = 1/2  # 第一项
    sum_series = 0  # 累积和
    
    for n in range(1, 100):  # 计算前99项
        sum_series += a 
        sequence_str = " + ".join([f"1/{2**i}" for i in range(1, n+1)])
        file.write(f"{sequence_str} = {sum_series}\n")
        a /= 2

print(f"已将结果写入到 {filename}")